import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:raze/artifacts/auth_portal_dialog.dart';
import 'package:raze/artifacts/diary_deletion_dialog.dart';
import 'package:raze/artifacts/signature_edit_dialog.dart';
import 'package:raze/artifacts/void_placeholder_widget.dart';
import 'package:raze/artifacts/notifier_glimmer.dart';
import 'package:raze/lore/chronicle/community_chronicle.dart';
import 'package:raze/lore/chronicle/qna_chronicle.dart';
import 'package:raze/lore/chronicle/user_chronicle.dart';
import 'package:raze/lore/chronicle/whisper_chronicle.dart';
import 'package:raze/potions/raze_constant.dart';
import 'package:raze/potions/spatial_alchemy.dart';

/// 我的页面
class MyHomeRealms extends StatefulWidget {
  const MyHomeRealms({super.key});

  @override
  State<MyHomeRealms> createState() => _MyHomeRealmsState();
}

class _MyHomeRealmsState extends State<MyHomeRealms>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  final Random _random = Random();

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final userChronicle = Get.find<UserChronicle>();
    final communityChronicle = Get.find<CommunityChronicle>();
    final qnaChronicle = Get.find<QnAChronicle>();

    return Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage('assets/images/background.png'),
          fit: BoxFit.cover,
        ),
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        body: Obx(() {
          final currentUser = userChronicle.currentUser;

          if (currentUser == null) {
            // 未登录状态
            return SafeArea(child: _constructNotLoggedInView());
          }

          // 已登录状态
          return _constructLoggedInView(
            currentUser,
            communityChronicle,
            qnaChronicle,
            userChronicle,
          );
        }),
      ),
    );
  }

  /// 构建未登录视图
  Widget _constructNotLoggedInView() {
    return Center(
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 32.w),
        child: Column(
          children: [
            100.h.boxHeight,
            // 装饰图片
            Image.asset(
              'assets/images/empty-status.png',
              width: 200.w,
              height: 200.w,
              fit: BoxFit.contain,
            ),

            // 提示文字容器
            Container(
              padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.h),
              decoration: BoxDecoration(
                color: RazeConstants.white,
                borderRadius: BorderRadius.circular(16.r),
                border: Border.all(color: RazeConstants.black, width: 2.w),
              ),
              child: Text('Please login to view your profile')
                  .applyTypeSize(16.sp)
                  .applyTypeColor(RazeConstants.black)
                  .applyNotoSans(weight: FontWeight.w500),
            ).withRightBottomShadow(thickness: 1),

            16.h.boxHeight,

            // 前往登录按钮
            Container(
                  padding: EdgeInsets.symmetric(
                    horizontal: 24.w,
                    vertical: 12.h,
                  ),
                  decoration: BoxDecoration(
                    color: RazeConstants.yellow,
                    borderRadius: BorderRadius.circular(12.r),
                    border: Border.all(color: RazeConstants.black, width: 2.w),
                  ),
                  child: Text('Go to Login')
                      .applyTypeSize(16.sp)
                      .applyTypeColor(RazeConstants.black)
                      .applyNotoSans(weight: FontWeight.w600),
                )
                .withRightBottomShadow(thickness: 1.5)
                .withTouchResonance(
                  onTap: () {
                    Get.toNamed('/login');
                  },
                ),
          ],
        ),
      ),
    );
  }

  /// 构建已登录视图
  Widget _constructLoggedInView(
    dynamic currentUser,
    CommunityChronicle communityChronicle,
    QnAChronicle qnaChronicle,
    UserChronicle userChronicle,
  ) {
    // 计算统计数据
    final publishedCommunities =
        communityChronicle.communityList
            .where((c) => c.userId == currentUser.id)
            .toList();
    // 获取用户点赞的社区列表（通过检查 likeList）
    final likedCommunities =
        communityChronicle.communityList
            .where(
              (c) =>
                  communityChronicle.checkCommunityLiked(currentUser.id, c.id),
            )
            .toList();
    // 获取用户点赞的问答列表
    final likedQuestionIds =
        qnaChronicle.questionList
            .where((q) => qnaChronicle.checkQuestionLiked(currentUser.id, q.id))
            .map((q) => q.id)
            .toList();
    final likedQuestions =
        likedQuestionIds
            .map((id) => qnaChronicle.queryQuestionById(id))
            .whereType<dynamic>()
            .toList();

    final worksCount = publishedCommunities.length;
    final collectionCount = likedCommunities.length;
    final likeCount = likedQuestions.length;

    return Stack(
      children: [
        // 可滚动内容
        SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // 用户信息和统计数据容器（黄色背景，底部圆角，顶部与屏幕顶部重合）
              Container(
                decoration: BoxDecoration(
                  color: RazeConstants.yellow,
                  borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(50.r),
                    bottomRight: Radius.circular(50.r),
                  ),
                ),
                child: Column(
                  children: [
                    // 用户信息区域（顶部留出导航栏空间）
                    Padding(
                      padding: EdgeInsets.only(
                        top: MediaQuery.of(context).padding.top + 20.h,
                      ),
                      child: _constructUserInfoSection(
                        currentUser,
                        userChronicle,
                      ),
                    ),

                    // 统计数据区域
                    _constructStatisticsSection(
                      worksCount,
                      collectionCount,
                      likeCount,
                    ),

                    30.h.boxHeight,
                  ],
                ),
              ).withRightBottomShadow(thickness: 2),

              // Tab 切换栏
              _constructTabBar(),

              // Tab 内容区域
              _constructTabBarView(
                publishedCommunities,
                likedCommunities,
                likedQuestions,
                communityChronicle,
                qnaChronicle,
              ),
            ],
          ),
        ),

        // 顶部固定导航栏（不随页面滚动，背景透明）
        Positioned(
          top: 0,
          left: 0,
          right: 0,
          child: SafeArea(
            bottom: false,
            child: _assembleTopNavigationBar(userChronicle),
          ),
        ),
      ],
    );
  }

  /// 组装顶部导航栏
  Widget _assembleTopNavigationBar(UserChronicle userChronicle) {
    final whisperChronicle = Get.find<WhisperChronicle>();

    return Obx(() {
      final currentUser = userChronicle.currentUser;
      final unreadCount =
          currentUser != null
              ? whisperChronicle.countTotalUnreadMessages(currentUser.id)
              : 0;

      return Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            // 设置按钮
            Container(
                  width: 30.w,
                  height: 30.w,
                  decoration: BoxDecoration(
                    color: RazeConstants.background,
                    border: Border.all(
                      color: RazeConstants.black,
                      width: 1.5.w,
                    ),
                    borderRadius: BorderRadius.circular(6.r),
                  ),
                  child: Icon(
                    Icons.settings_rounded,
                    size: 20.sp,
                    color: RazeConstants.black,
                  ),
                )
                .withRightBottomShadow(thickness: 1)
                .withTouchResonance(
                  onTap: () {
                    Get.toNamed('/settings');
                  },
                ),

            // 聊天按钮（参考 UserNavBarWidget）
            Stack(
              clipBehavior: Clip.none,
              children: [
                Container(
                      width: 30.w,
                      height: 30.w,
                      decoration: BoxDecoration(
                        color: RazeConstants.background,
                        border: Border.all(
                          color: RazeConstants.black,
                          width: 1.5.w,
                        ),
                        borderRadius: BorderRadius.circular(6.r),
                      ),
                      padding: EdgeInsets.all(4.w),
                      child: Image.asset(
                        'assets/images/message.png',
                        width: 16.w,
                        height: 16.w,
                      ),
                    )
                    .withRightBottomShadow(thickness: 1)
                    .withTouchResonance(
                      onTap: () {
                        if (!userChronicle.isLoggedIn) {
                          AuthPortalDialog.revealAuthPortal();
                          return;
                        }
                        Get.toNamed('/message-list');
                      },
                    ),
                if (unreadCount > 0)
                  Positioned(
                    right: -6.w,
                    top: -6.w,
                    child: Container(
                      padding: EdgeInsets.symmetric(
                        horizontal: 2.w,
                        vertical: 2.h,
                      ),
                      decoration: BoxDecoration(
                        color: RazeConstants.lightBlue,
                        shape: BoxShape.circle,
                        border: Border.all(
                          color: RazeConstants.black,
                          width: 1.5.w,
                        ),
                      ),
                      constraints: BoxConstraints(
                        minWidth: 18.w,
                        minHeight: 18.w,
                      ),
                      child: Center(
                        child: Text(
                          unreadCount > 99 ? '99+' : unreadCount.toString(),
                          style: TextStyle(
                            color: RazeConstants.black,
                            fontSize: 10.sp,
                            fontWeight: FontWeight.w400,
                          ),
                        ),
                      ),
                    ),
                  ),
              ],
            ),
          ],
        ),
      );
    });
  }

  /// 构建用户信息区域
  Widget _constructUserInfoSection(
    dynamic currentUser,
    UserChronicle userChronicle,
  ) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 10.h),
      child: Column(
        children: [
          // 用户头像
          Container(
            width: 80.w,
            height: 80.w,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              border: Border.all(color: RazeConstants.black, width: 2.w),
            ),
            child: ClipOval(
              child: Image.asset(
                currentUser.avatar,
                width: 80.w,
                height: 80.w,
                fit: BoxFit.cover,
              ),
            ),
          ),

          // 用户名
          Text(currentUser.username)
              .applyTypeSize(24.sp)
              .applyTypeColor(RazeConstants.black)
              .applyBagelFatOne(weight: FontWeight.w400),

          // 签名和编辑按钮
          GestureDetector(
            onTap: () {
              SignatureEditDialog.revealSignatureEdit(
                initialSignature: currentUser.signature,
                onSignatureUpdated: (newSignature) {
                  // 更新用户签名
                  final updatedUser = currentUser.copyWith(
                    signature: newSignature,
                  );
                  userChronicle.updateCurrentUser(updatedUser);
                  // 显示成功提示
                  NotifierGlimmer.revealSuccess(
                    'Signature updated successfully',
                  );
                },
              );
            },
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  constraints: BoxConstraints(maxWidth: 260.w),
                  child:
                      Text(
                            currentUser.signature,
                            maxLines: 2,
                            overflow: TextOverflow.ellipsis,
                            textAlign: TextAlign.center,
                          )
                          .applyTypeSize(12.sp)
                          .applyTypeColor(const Color(0xFF8F8F8F))
                          .applyNotoSans(),
                ),
                4.w.boxWidth,
                Image.asset(
                  'assets/images/edit.png',
                  width: 14.w,
                  height: 14.w,
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  /// 构建统计数据区域
  Widget _constructStatisticsSection(
    int worksCount,
    int collectionCount,
    int likeCount,
  ) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 38.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          // Works
          Expanded(child: _buildStatisticBox('$worksCount', 'Works')),
          SizedBox(width: 30.w),
          // Collection
          Expanded(child: _buildStatisticBox('$collectionCount', 'Collection')),
          SizedBox(width: 30.w),
          // Like
          Expanded(child: _buildStatisticBox('$likeCount', 'Like')),
        ],
      ),
    );
  }

  /// 构建单个统计框
  Widget _buildStatisticBox(String count, String label) {
    return AspectRatio(
      aspectRatio: 80 / 57,
      child: Container(
        decoration: BoxDecoration(
          color: RazeConstants.background,
          borderRadius: BorderRadius.circular(12.r),
          border: Border.all(color: RazeConstants.black, width: 1.w),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(count)
                .applyTypeSize(20.sp)
                .applyTypeColor(RazeConstants.black)
                .applyNotoSans(weight: FontWeight.w600),
            Text(label)
                .applyTypeSize(14.sp)
                .applyTypeColor(RazeConstants.black.withOpacity(0.6))
                .applyNotoSans(),
          ],
        ),
      ).withRightBottomShadow(thickness: 1),
    );
  }

  /// 构建 Tab 切换栏
  Widget _constructTabBar() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.h),
      decoration: BoxDecoration(
        color: RazeConstants.background,
        borderRadius: BorderRadius.circular(12.r),
        border: Border.all(color: RazeConstants.black, width: 1.w),
      ),
      padding: EdgeInsets.symmetric(horizontal: 4.w),
      child: Stack(
        children: [
          // 黄色指示器容器（固定宽高）
          AnimatedBuilder(
            animation: _tabController,
            builder: (context, child) {
              final index = _tabController.index;
              final screenWidth = MediaQuery.of(context).size.width;
              final containerWidth = screenWidth - 32.w - 8.w;
              final tabWidth = containerWidth / 3;

              return Positioned(
                left: index * tabWidth + 4.w,
                top: 4.w,
                bottom: 4.w,
                child: Container(
                  width: tabWidth - 8.w,
                  height: 38.h,
                  decoration: BoxDecoration(
                    color: RazeConstants.yellow,
                    borderRadius: BorderRadius.circular(6.r),
                    border: Border.all(color: RazeConstants.black, width: 1.w),
                  ),
                ),
              );
            },
          ),

          // Tab 内容
          TabBar(
            controller: _tabController,
            indicator: const BoxDecoration(),
            indicatorSize: TabBarIndicatorSize.tab,
            indicatorColor: Colors.transparent,
            dividerColor: Colors.transparent,
            labelColor: RazeConstants.black,
            unselectedLabelColor: RazeConstants.black.withOpacity(0.6),
            labelStyle: TextStyle(
              fontSize: 14.sp,
              fontFamily:
                  GoogleFonts.notoSansSc(
                    fontWeight: FontWeight.w600,
                  ).fontFamily,
              fontWeight: FontWeight.w600,
            ),
            unselectedLabelStyle: TextStyle(
              fontSize: 14.sp,
              fontFamily:
                  GoogleFonts.notoSansSc(
                    fontWeight: FontWeight.w400,
                  ).fontFamily,
              fontWeight: FontWeight.w400,
            ),
            tabs: const [
              Tab(text: 'Works'),
              Tab(text: 'Like'),
              Tab(text: 'Q&A'),
            ],
          ),
        ],
      ),
    ).withRightBottomShadow(thickness: 1);
  }

  /// 构建 Tab 内容区域
  Widget _constructTabBarView(
    List publishedCommunities,
    List likedCommunities,
    List likedQuestions,
    CommunityChronicle communityChronicle,
    QnAChronicle qnaChronicle,
  ) {
    // 使用 LayoutBuilder 获取最大高度
    return LayoutBuilder(
      builder: (context, constraints) {
        // 计算三个 Tab 的高度，取最大值
        final worksHeight = _calculateTabHeight(
          publishedCommunities.length,
          constraints.maxWidth,
        );
        final collectionHeight = _calculateTabHeight(
          likedCommunities.length,
          constraints.maxWidth,
        );
        final likeHeight = _calculateTabHeight(
          likedQuestions.length,
          constraints.maxWidth,
        );

        final maxHeight = [
          worksHeight,
          collectionHeight,
          likeHeight,
        ].reduce((a, b) => a > b ? a : b);

        return SizedBox(
          height: maxHeight,
          child: TabBarView(
            controller: _tabController,
            physics: const NeverScrollableScrollPhysics(), // 禁用滑动
            children: [
              // Works Tab: 用户发布的 community 列表
              _buildCommunityGrid(
                publishedCommunities,
                communityChronicle,
                isUserPublished: true,
              ),
              // Collection Tab: 用户点赞的 community 列表
              _buildCommunityGrid(
                likedCommunities,
                communityChronicle,
                isUserPublished: false,
              ),
              // Like Tab: 用户点赞的问答列表
              _buildQuestionGrid(likedQuestions, qnaChronicle),
            ],
          ),
        );
      },
    );
  }

  /// 计算 Tab 高度
  double _calculateTabHeight(int itemCount, double availableWidth) {
    if (itemCount == 0) {
      return 200.h; // 空状态最小高度
    }

    // 固定三列
    final itemsPerRow = 3;
    final rows = (itemCount / itemsPerRow).ceil();

    // 项宽高比 110/150，考虑间距
    final itemHeight = 150.w;
    final spacing = 8.w;
    return rows * (itemHeight + spacing) + spacing + 32.h; // 加上间距和 padding
  }

  /// 构建 Community 网格
  Widget _buildCommunityGrid(
    List communities,
    CommunityChronicle communityChronicle, {
    required bool isUserPublished,
  }) {
    if (communities.isEmpty) {
      return Padding(
        padding: EdgeInsets.symmetric(vertical: 40.h),
        child: VoidPlaceholderWidget(message: 'No items yet'),
      );
    }

    return Padding(
      padding: EdgeInsets.only(
        left: 16.w,
        right: 16.w,
        top: 0.h,
        bottom: 140.h,
      ),
      child: LayoutBuilder(
        builder: (context, constraints) {
          final availableWidth = constraints.maxWidth;
          final spacing = 8.w;
          final totalSpacing = spacing * 2; // 两个间距（三个项之间）
          final itemsPerRow = 3; // 固定三列
          final calculatedItemWidth =
              (availableWidth - totalSpacing) / itemsPerRow;

          return Wrap(
            spacing: spacing,
            runSpacing: spacing,
            alignment: WrapAlignment.start,
            children:
                communities.map((community) {
                  return SizedBox(
                    width: calculatedItemWidth,
                    child: _buildCommunityGridItem(
                      community,
                      communityChronicle,
                      isUserPublished: isUserPublished,
                    ),
                  );
                }).toList(),
          );
        },
      ),
    );
  }

  /// 构建单个 Community 网格项
  Widget _buildCommunityGridItem(
    dynamic community,
    CommunityChronicle communityChronicle, {
    required bool isUserPublished,
  }) {
    final viewCount = _random.nextInt(500) + 50; // 随机查看次数

    return AspectRatio(
      aspectRatio: 110 / 150,
      child: GestureDetector(
        onTap: () {
          // 跳转到社区详情页
          Get.toNamed(
            '/community-detail',
            parameters: {'communityId': community.id},
          );
        },
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10.r),
            border: Border.all(color: RazeConstants.black, width: 1.w),
          ),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(10.r),
            child: Stack(
              children: [
                // 背景图片（宽高比 171/229）
                Positioned.fill(
                  child: AspectRatio(
                    aspectRatio: 171 / 229,
                    child:
                        community.contentType == 'video'
                            ? Stack(
                              fit: StackFit.expand,
                              children: [
                                // 视频封面
                                Image.asset(
                                  community.coverImage ?? community.media,
                                  fit: BoxFit.cover,
                                ),
                                // 播放图标
                                Center(
                                  child: // 播放图标
                                      Container(
                                    width: 30.w,
                                    height: 30.w,
                                    decoration: BoxDecoration(
                                      color: RazeConstants.white.withOpacity(
                                        0.9,
                                      ),
                                      shape: BoxShape.circle,
                                      border: Border.all(
                                        color: RazeConstants.black,
                                        width: 2.w,
                                      ),
                                    ),
                                    child: Icon(
                                      Icons.play_arrow_rounded,
                                      size: 20.w,
                                      color: RazeConstants.black,
                                    ),
                                  ).withRightBottomShadow(thickness: 1.5),
                                ),
                              ],
                            )
                            : Image.asset(community.media, fit: BoxFit.cover),
                  ),
                ),

                // 删除按钮（右上角）
                if (isUserPublished)
                  Positioned(
                    top: 4.w,
                    right: 4.w,
                    child: GestureDetector(
                      onTap: () {
                        DiaryDeletionDialog.revealDeletionConfirmation(
                          onConfirm: () {
                            communityChronicle.deleteCommunityById(
                              community.id,
                            );
                            setState(() {}); // 刷新页面
                          },
                        );
                      },
                      child: Container(
                        width: 24.w,
                        height: 24.w,
                        decoration: BoxDecoration(
                          color: RazeConstants.yellow,
                          borderRadius: BorderRadius.circular(4.r),
                          border: Border.all(
                            color: RazeConstants.black,
                            width: 1.w,
                          ),
                        ),
                        padding: EdgeInsets.all(5.w),
                        child: Image.asset(
                          'assets/images/delete.png',
                          width: 14.w,
                          height: 14.w,
                        ),
                      ).withRightBottomShadow(thickness: 0.5),
                    ),
                  ),

                // 底部渐变蒙层
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    height: 40.h,
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Colors.transparent,
                          Colors.black.withOpacity(0.3),
                        ],
                      ),
                    ),
                  ),
                ),

                // 查看次数（右下角）
                Positioned(
                  bottom: 4.w,
                  right: 4.w,
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Icon(
                        Icons.visibility_rounded,
                        size: 16.sp,
                        color: RazeConstants.white,
                      ),
                      4.w.boxWidth,
                      Text('$viewCount')
                          .applyTypeSize(12.sp)
                          .applyTypeColor(RazeConstants.white)
                          .applyNotoSans(weight: FontWeight.w600),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  /// 构建 Question 网格
  Widget _buildQuestionGrid(List questions, QnAChronicle qnaChronicle) {
    if (questions.isEmpty) {
      return Padding(
        padding: EdgeInsets.symmetric(vertical: 40.h),
        child: VoidPlaceholderWidget(message: 'No items yet'),
      );
    }

    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
      child: LayoutBuilder(
        builder: (context, constraints) {
          final availableWidth = constraints.maxWidth;
          final spacing = 8.w;
          final totalSpacing = spacing * 2; // 两个间距（三个项之间）
          final itemsPerRow = 3; // 固定三列
          final calculatedItemWidth =
              (availableWidth - totalSpacing) / itemsPerRow;

          return Wrap(
            spacing: spacing,
            runSpacing: spacing,
            alignment: WrapAlignment.start,
            children:
                questions.map((question) {
                  return SizedBox(
                    width: calculatedItemWidth,
                    child: _buildQuestionGridItem(question, qnaChronicle),
                  );
                }).toList(),
          );
        },
      ),
    );
  }

  /// 构建单个 Question 网格项
  Widget _buildQuestionGridItem(dynamic question, QnAChronicle qnaChronicle) {
    return AspectRatio(
      aspectRatio: 110 / 150,
      child: GestureDetector(
        onTap: () {
          // 跳转到问答详情页
          Get.toNamed(
            '/knowledge-discourse',
            parameters: {'questionId': question.id},
          );
        },
        child: Container(
          padding: EdgeInsets.all(8.w),
          decoration: BoxDecoration(
            color: RazeConstants.white,
            borderRadius: BorderRadius.circular(10.r),
            border: Border.all(color: RazeConstants.black, width: 1.w),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              // 问题内容
              Expanded(
                child:
                    Text(
                          question.content,
                          maxLines: 6,
                          overflow: TextOverflow.ellipsis,
                        )
                        .applyTypeSize(12.sp)
                        .applyTypeColor(RazeConstants.black)
                        .applyNotoSans(),
              ),
              // 点赞数
              Row(
                children: [
                  Icon(
                    Icons.favorite_rounded,
                    size: 12.sp,
                    color: RazeConstants.red,
                  ),
                  4.w.boxWidth,
                  Text('${question.likeCount}')
                      .applyTypeSize(12.sp)
                      .applyTypeColor(RazeConstants.black)
                      .applyNotoSans(),
                ],
              ),
            ],
          ),
        ).withRightBottomShadow(thickness: 1),
      ),
    );
  }
}
